package example.rmi.server.handler.impl;

import example.rmi.stub.entity.User;
import example.rmi.stub.handler.UserService;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

/**
 * @author Hao Yang
 */
public class UserServiceImpl extends UnicastRemoteObject implements UserService {

    private static UserService instance;

    static {
        try {
            instance = new UserServiceImpl();
        } catch (RemoteException e) {
            e.printStackTrace();
        }
    }

    protected UserServiceImpl() throws RemoteException {
    }

    public static UserService getInstance(){
        return UserServiceImpl.instance;
    }

    public String getNameById(int id) throws RemoteException{
        return "yanghao";
    }

    public User getUserById(int id) throws RemoteException{
        return new User(1,"yanghao",25);
    }

}
